package com.exer.dataload;


import com.exer.dataload.DorisDDLConverter.impl.DorisDDLConverterFromMySQL;
import com.exer.dataload.log.DorisDataLoadLog;

public class Main {

    /**
     * 测试前请保证mysql表存在
     * @param args
     */
    public static void main(String[] args) {
        String tableName = "me_points_record";
        dorisDataLoadByStreamLoadFullTest(tableName);
    }


    /**
     * 测试正常流程
     */
    public static void test(String tableName) {
        DorisDataLoad dataLoad = DorisDataLoadLog.getLogProxyObject(new DorisDataLoaderFromMySQL(tableName), DorisDataLoad.class);
        //doris是否存在该表
        if (dataLoad.dorisTableExistenceChecker()) {
            //增量同步,若表中无数据直接全量同步
            long count = dataLoad.getDorisTableCount();
            if (count != 0) {
                dataLoad.dorisDataLoadByStreamLoadIncremental();
            } else {
                dataLoad.dorisDataLoadByStreamLoadFull();
            }
        } else {
            //不存在则创建,并全量同步
            DorisDDLConverterFromMySQL mysqlDDLToDorisDDL = new DorisDDLConverterFromMySQL(tableName);
            boolean createResult = dataLoad.createDorisTable(mysqlDDLToDorisDDL.getDorisDDL());
            if (!createResult) {
                throw new RuntimeException("创建doris表失败");
            }
            dataLoad.dorisDataLoadByStreamLoadFull();
        }
    }

    /**
     * 测试找出id数据集差异并添加到doris
     */
    public static void dorisDataLoadByIdDifferencesTest(String tableName) {
        DorisDataLoad dataLoad = DorisDataLoadLog.getLogProxyObject(new DorisDataLoaderFromMySQL(tableName), DorisDataLoad.class);
        dataLoad.dorisDataLoadByIdDifferences();
    }

    /**
     * 测试全量同步InsertInto方式
     */
    public static void dorisDataLoadByInsertIntoFullTest(String tableName) {
        DorisDataLoad dataLoad = DorisDataLoadLog.getLogProxyObject(new DorisDataLoaderFromMySQL(tableName), DorisDataLoad.class);
        dataLoad.dorisDataLoadByInsertIntoFull();
    }

    /**
     * 测试全量同步StreamLoad方式
     */
    public static void dorisDataLoadByStreamLoadFullTest(String tableName) {
        DorisDataLoad dataLoad = DorisDataLoadLog.getLogProxyObject(new DorisDataLoaderFromMySQL(tableName), DorisDataLoad.class);
        dataLoad.dorisDataLoadByStreamLoadFull();
        ;
    }

    /**
     * 测试增量同步StreamLoad方式
     */
    public static void dorisDataLoadByStreamLoadIncrementalTest(String tableName) {
        DorisDataLoad dataLoad = DorisDataLoadLog.getLogProxyObject(new DorisDataLoaderFromMySQL(tableName), DorisDataLoad.class);
        dataLoad.dorisDataLoadByStreamLoadIncremental();
    }

    /**
     * 测试增量同步InsertInto方式
     */
    public static void dorisDataLoadByInsertIntoIncrementalTest(String tableName) {
        DorisDataLoad dataLoad = DorisDataLoadLog.getLogProxyObject(new DorisDataLoaderFromMySQL(tableName), DorisDataLoad.class);
        dataLoad.dorisDataLoadByInsertIntoIncremental();
    }


}
